package com.senney.bio;

import java.io.IOException;
import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.net.Socket;

/**
 * @author Lanmengye@outlook.com
 * @date 2021/1/2 22:00
 */
public class BIOClient {
    public static void main(String[] args){
        for (int i = 0; i < 5; i++) {
            new Thread(() -> {
                Socket socket = new Socket();
                try {
                    socket.connect(new InetSocketAddress("127.0.0.1", 6666));
                    OutputStream outputStream = socket.getOutputStream();
                    outputStream.write(("from client: " + socket.getLocalPort()).getBytes());
                } catch (IOException e) {
                    e.printStackTrace();
                } finally {
                    try {
                        socket.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }).start();
        }
    }
}
